package com.demo.dto;

import java.util.List;


public class Pager<T> {
	//自变量
	private List<T> data;
	private int page = 1; // 当前页
	private int rows = 10; // 每页多少行
	private int totalRow; // 共多少行
	//因变量
	private int totalPage; // 共多少页
	private int start;// 当前页起始行
	private int end;// 当前页结束行
	
	public void setRows(int rows) {
		this.rows = rows;
	}

	public void setPage(int page) {
		if (page < 1) {
			page = 1;
		} else {
			start = rows * (page - 1);
		}
		end = start + rows > totalRow ? totalRow : start + rows;
		this.page = page;
	}

	public void setTotalRow(int totalRow) {
		totalPage = (totalRow + rows - 1) / rows;
		this.totalRow = totalRow;
		if (totalPage < page) {
			page = totalPage;
			start = rows * (page - 1);
			end = totalRow;
		}
		end = start + rows > totalRow ? totalRow : start + rows;
	}

	public void setData(List<T> data) {
		this.data = data;
	}

	public List<T> getData() {
		return data;
	}

	public int getPage() {
		return page;
	}

	public int getRows() {
		return rows;
	}

	public int getTotalRow() {
		return totalRow;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public int getStart() {
		return start;
	}

	public int getEnd() {
		return end;
	}
	
}
